﻿using AutoMapper;
using MediatR;
using SheepStorage.API.Application.Command.SheepPurchaseCommand;
using SheepStorage.API.Baseclass;
using SheepStorage.Domain.Entity;
using SheepStorage.Service.Interface;

namespace SheepStorage.API.Application.CommandHandlers.SheepPurchaseHandler
{
    public class SheepPurchaseDeleteHandler:IRequestHandler<SheepPurchaseDeleteCommand,Results<int>>
    {
        private readonly ISheepPurchaseService _purchaseService;
        private readonly IMapper _mapper;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="purchaseService"></param>
        /// <param name="mapper"></param>
        public SheepPurchaseDeleteHandler(ISheepPurchaseService purchaseService,IMapper mapper)
        {
            _purchaseService = purchaseService;
            _mapper = mapper;
        }

        /// <summary>
        /// 批量删除/逻辑删除
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Results<int>> Handle(SheepPurchaseDeleteCommand request, CancellationToken cancellationToken)
        {
            var result = await _purchaseService.DeleteSheepPurchase(request.PurchaseId.ToArray());

            return Results<int>.DataResult(result);
        }
    }
}
